#pragma once
#include<vector>
#include<algorithm>
#include<iostream>
#include<queue>

using namespace std;
namespace ljw
{
	template<class T,class Cantainer=vector<T>,class compare=less<T>>
	class priority_queue
	{
	public:
		void adjust_up(size_t child)
		{
			compare con;
			size_t pather = (child - 1) / 2;
			while (child > 0)
			{
				//if (_con[pather] < _con[child])
				if(con(_con[pather],_con[child]))
				{
					swap(_con[pather], _con[child]);
					child = pather;
					pather = (child - 1) / 2;
				}
				else
				{
					break;
				}
			}
		}
		void adjust_down(size_t pather)
		{
			compare con;
			size_t child = pather * 2 + 1;
			while (child < _con.size())
			{
				/*if (child + 1 < _con.size() &&
					_con[child]<_con[child+1])*/
				if(child+1<_con.size()&&
					con(_con[child] ,_con[child + 1]))
				{
					child++;
				}
				if (con(_con[pather] ,_con[child]))
				{
					swap(_con[pather], _con[child]);
					pather = child;
					child = pather * 2 + 1;
				}
				else
				{
					break;
				}
			}
		}
		void push(const T& x)
		{
			_con.push_back(x);
			adjust_up(_con.size() - 1);
		}
		void pop()
		{
			swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			adjust_down(0);
		}
		bool empty()
		{
			return _con.empty();
		}
		const T& top()
		{
			return _con[0];
		}
		size_t size()
		{
			return _con.size();
		}
	private:
		Cantainer _con;
	};
}